package com.dhcc.DRGsHosp.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.openkoala.koala.commons.InvokeResult;
import org.openkoala.security.shiro.CurrentUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.DRGsHosp.facade.ICDFacade;
import org.codehaus.jackson.map.ObjectMapper;

/**
 * @title		:ICDController.java
 * @description	:
 * @author		:lileizheng
 * @date		:2015年8月12日
 * @version     :1.0
 * @copyright   :DHCC 2013-2014 
 */
@Controller("drgsHospWebController23")
@RequestMapping("/ICD")
public class ICDController {

	@Autowired
	private ICDFacade icdFacade;
	
	@ResponseBody
	@RequestMapping(value = "matchICD")
	public InvokeResult matchICD(String icdVersion, String icdType){
		String userCode = CurrentUser.getUserAccount();
		return icdFacade.matchICD(icdVersion, userCode, icdType);
	}
	
	@ResponseBody
	@RequestMapping(value = "getICDMatchResult")
	public InvokeResult getICDMatchResult(String icdVersion, String icdType, String depCode){
		return icdFacade.getICDMatchResult(icdVersion, icdType, depCode);
	}
	
	@ResponseBody
	@RequestMapping(value = "getICDMatching")
	public InvokeResult getICDMatching(String param){
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, Object> json;
		try {
			json = objectMapper.readValue(param, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
			json = new HashMap<String, Object>();
		} 
		return icdFacade.getICDMatching(json);
	}
	
	@ResponseBody
	@RequestMapping(value = "getBJICD")
	public Object getBJICD(String icdType, String icdVersion, String icdValue, String icdValue1){
		return icdFacade.getBJICD(icdType, icdVersion, icdValue, icdValue1);
	}
	
	@ResponseBody
	@RequestMapping(value = "updateICDMatching")
	public InvokeResult updateICDMatching(String param){
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, Object> json = new HashMap<>();
		try {
			json = objectMapper.readValue(param, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		json.put("userCode", CurrentUser.getUserAccount());
		return icdFacade.updateICDMatching(json);
	}
	
	@ResponseBody
	@RequestMapping(value = "getEditLog")
	public InvokeResult getEditLog(String hICDCode, String icdVersion){
		return icdFacade.getEditLog(hICDCode, icdVersion);
	}
	
	@ResponseBody
	@RequestMapping(value = "icdImport")
	public InvokeResult icdImport(String icdType, String param){
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, Object> json = new HashMap<>();
		try {
			json = objectMapper.readValue(param, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		json.put("userCode", CurrentUser.getUserAccount());
		return icdFacade.icdImport(icdType, json);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getICDMatchResultTable")
	public InvokeResult getICDMatchResultTable(String icdType, String isOnlyMatch){
		return icdFacade.getICDMatchResultTable(icdType, isOnlyMatch);
	}

	/**
	 * @description 查找诊断字典
	 * @param condition
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/findDiags")
	public List<Map<String, Object>> findDiags(String condition){
		return icdFacade.findDiags(condition);
	}

	/**
	 * @description 查找手术字典
	 * @param condition
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/findOpers")
	public List<Map<String, Object>> findOpers(String condition){
		return icdFacade.findOpers(condition);
	}
}
